CROSS_COMPILE := /usr/bin/aarch64-linux-gnu-
TARGET := myServer
CURRENT_DIR := $(shell pwd)

CC := $(CROSS_COMPILE)gcc-9
# CXX := $(CROSS_COMPILE)g++-9

CFLAGS := -Wall -g -O2 -D_GNU_SOURCE
CXXFLAGS := -Wall -g -O2 -D_GNU_SOURCE

#库的名字是去掉lib前缀，去掉.so或.a后缀 如-lrkaiq就是库librkaiq.so
# LDLIBS := -lrkaiq -ldl
# LIBPATH := $(CURRENT_DIR)/lib
# LDFLAGS := -L$(LIBPATH) -pthread


#递归获取所有目录的路径  形式是相对于CURRENT_DIR的路径 ./dir
ALL_DIRS := $(sort $(shell find $(CURRENT_DIR) -type d))

INCLUDE := $(patsubst %, -I %, $(ALL_DIRS))

CFILES	:= $(foreach dir, $(ALL_DIRS), $(wildcard $(dir)/*.c))

SRCS := $(notdir $(CFILES))

#这里添加obj的意思是中间目标都变成了obj/***.o，其生成后就会统一存放到obj文件夹下
OBJS := $(patsubst %, obj/%, $(SRCS:.c=.o))

#指定源文件搜索路径
VPATH := $(ALL_DIRS)

$(TARGET) : $(OBJS)
	$(CC) -pthread -o $@ $^ 

$(OBJS) : obj/%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $< 

.PHONY : clean

clean:
	rm -rf $(TARGET) $(OBJS)

.PHONY : printf

printf:
	@echo CURRENT_DIR=$(CURRENT_DIR)
	@echo ALL_DIRS=$(ALL_DIRS)
	@echo CFILES=$(CFILES)
	@echo INCLUDE=$(INCLUDE)
	@echo SRCS=$(SRCS)
	@echo OBJS=$(OBJS)
	# @echo LDLIBS=$(LDLIBS)
	# @echo LIBPATH=$(LIBPATH)
	# @echo LDFLAGS=$(LDFLAGS)
	





